<?php

class M_department Extends MY_Model
{

	public function insert($data)
	{
		
		$input['department_desc'] = $data['description'];
		$input['department_name'] = $data['name'];
		$input['created_at'] = NOW;

		$this->db->insert(parent::$dep_table,$input);
		return $this->db->affected_rows() >= 1 ? TRUE : FALSE;
	}
	
	public function get($id = FALSE)
	{
		if(is_numeric($id) AND $id !== FALSE)
		{
			$query = $this->db->select('id,department_name,department_desc')
							->where('id',$id)
							->get(parent::$dep_table);
			return $query->num_rows() >= 1 ? $query->row() : FALSE;
		}else{
			$query = $this->db->select('id,department_name,department_desc')
								->get(parent::$dep_table);
			return $query->num_rows() >= 1 ? $query->result() : FALSE;
		}
	}
	
	public function get_department_array()
	{
		$data = $this->get();
	
	
		if(!empty($data))
		{
			$opt[''] = '-- Choose Department --';
			foreach($data as $v)
			{
				$opt[$v->id] = ucwords($v->department_name);
			}
		}else{
			$opt[''] = 'No Department Found';
		}
	
		return $opt;
	}
	
	public function fetch_dept($start,$limit)
	{
		$start = is_numeric($start) ? intval($start) : 0;
		$limit = is_numeric($limit) ? intval($limit) : 10;
		$query = $this->db->select('id,department_name,department_desc')
									->limit($start,$limit)
									->get(parent::$dep_table);
		return $query->num_rows() >= 1 ? $query->result() : FALSE;
	}
	
	
	public function update()
	{
		
	}
	
	public function delete()
	{
	
	
	}
	
	public function count_dept()
	{
		return $this->db->count_all(parent::$dep_table);
	}





}